/*
 * AbstractGameObject.java
 *
 * Created on 27. April 2007, 20:12
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package de.tor.obj;

import com.golden.gamedev.object.AnimatedSprite;
import de.tor.obj.action.AbstractMovement;
import java.awt.image.BufferedImage;

/**
 *
 * @author Charon
 */
public abstract class AbstractAnimatedGameObject extends AnimatedSprite {
    
    private AbstractMovement mMovement = null;
    private int iHealth = 0;
    private boolean bIsDestructable = false;
    
    public AbstractAnimatedGameObject(BufferedImage[] images){
        super(images);
        setAnimate(true);
        setLoopAnim(true);
    }
    
    public AbstractAnimatedGameObject(BufferedImage[] images, double x, double y){
        super(images, x, y);
        setAnimate(true);
        setLoopAnim(true);
        iHealth = getMaxHealth();
    }
    
    public void setMovement(AbstractMovement pMovement){
        mMovement = pMovement;
        mMovement.setParent(this);
    }
    
    public boolean isDestructable(){
        return bIsDestructable;
    }
    
    public void setDestructable(boolean v){
        bIsDestructable = v;
    }
    
    public abstract int getMaxHealth();
    
    public int getHealth(){
        return iHealth;
    }
    
    public void addHealth(int v){
        iHealth += v;
        if(iHealth > getMaxHealth()) iHealth = getMaxHealth();
    }
    
    public void doDamage(int v){
        iHealth -= v;
    }
    
    public boolean isDestroyed(){
        return (iHealth <= 0);
    }
    
    public boolean isOnScreen(){
        return (getScreenY() >= 0);
    }
    
    public void update(long elapsedTime){
        if(mMovement != null){
            mMovement.update(elapsedTime);
            setHorizontalSpeed(mMovement.getHorizontalSpeed());
            setVerticalSpeed(mMovement.getVerticalSpeed());
            setLocation(mMovement.getXPos(), mMovement.getYPos());
            super.update(elapsedTime);
        }else{
            super.update(elapsedTime);
        }
    }
}
